<?php
require_once(SITE_ROOT."/includes/User.php");
require_once(SITE_ROOT."/includes/checksession.php");
require_once(SITE_ROOT."/includes/application/FriendsApplication.php");
require_once(SITE_ROOT."/includes/application/ScripApplication.php");
require_once(SITE_ROOT."/includes/application/GreetApplication.php");
require_once(SITE_ROOT."/includes/component/NewNotificationPageComponent.php");
require_once(SITE_ROOT."/includes/component/StatusBarKooPoint.php");
require_once("Ajax.php");

class AutoGetTipAjax extends Ajax {
    public function prepare() {
        global $gSmarty,$G_LANG,$G_SKIN;
        check_login_forajax();
        $userid = $_SESSION['G_USERID'];
        $user = FaceKoo::getElementObject(0);
        
        // 读取在线好友个数
        if($_SESSION['G_USERID']!=3&&$_SESSION['G_USERID']!=607){
            $app = FaceKoo::getElementObject(6);
            $friendsList = $app->getOnlineFriendsForNavigator($_SESSION['G_USERID']);
            if(is_array($friendsList[1]))
            {
                foreach($friendsList[1] as &$row)
                {
                    $row['nickname'] = htmlspecialchars($row['nickname']);
                    $row['mainphoto'] = $user->getUserMainphoto($row['id'],$row['mainphoto'],60);
                }
                $getTipAjaxJson['online_friends_num'] = $friendsList[0];
                $getTipAjaxJson['online_friends'] = $friendsList[1];
            } else {
                $getTipAjaxJson['online_friends_num'] = 0;
                $getTipAjaxJson['online_friends'] = "";
            }
        }
        

        // 读取新的好友请求数量以及最新的N个好友请求
        $app = FaceKoo::getElementObject(6);
        $invites_friends_num = $app->getTotalOfInvitedFriends($userid);
        $invites_friends_list = $app->getInvitedFriendsList($userid,0,5);
        foreach($invites_friends_list->recordArray as &$row) {
            $row['nickname'] = htmlspecialchars($row['nickname']);
            $row['mainphoto'] = $user->getUserMainphoto($row['id'],$row['mainphoto'],60);
        }
        $getTipAjaxJson['invites_friends_num'] = $invites_friends_num;
        $getTipAjaxJson['invites_friends_list'] = $invites_friends_list->recordArray;
        
        // 读取当前自己是否在线        
        if( $user->getOnlineStatus($_SESSION['G_USERID']) == 0 ) {
            $getTipAjaxJson['mymood'] = "0";
        } else {
            $mydetail = $user->getUserDetail($_SESSION['G_USERID']);
            $getTipAjaxJson['mymood'] = $mydetail['mood'];
        }
        
        // 读取未读小纸条数
        $app = FaceKoo::getElementObject(2);
        $scripArray = $app->getUnreadScrip($_SESSION['G_USERID']);
        for($i=0;$i<count($scripArray);$i++) {            
            $scripArray[$i]['nickname'] = htmlspecialchars($scripArray[$i]['nickname']);
        }
        if(is_array($scripArray))
            $getTipAjaxJson['scripttip'] = $scripArray;
        else 
            $getTipAjaxJson['scripttip'] = "";
            
        // 读取新的小纸条
        $scripArray = $app->getScripTip($_SESSION['G_USERID']);
        for($i=0;$i<count($scripArray);$i++) {            
            $scripArray[$i]['nickname'] = htmlspecialchars($scripArray[$i]['nickname']);
        }
        if(is_array($scripArray))
            $getTipAjaxJson['newscripttip'] = $scripArray;
        else 
            $getTipAjaxJson['newscripttip'] = "";
        
        // 读取新的大事件
        $app = new NewNotificationPageComponent();
        $notifycation = $app->prepare();
        $getTipAjaxJson['notifycation'] = $notifycation;
        
        // 获取KOO分栏内容
        $app = new StatusBarKooPoint();
        $statusBarKooPoint = $app->prepare();
        $getTipAjaxJson['koopoint'] = $statusBarKooPoint;
        //取得广告
        $admsg=$user->getAdMsg();
        if($admsg!=false){
        $getTipAjaxJson['haveadmsg']="1";
        $getTipAjaxJson['admsg']=$admsg['admsg'];
        $getTipAjaxJson['adpic']=$admsg['adpic'];
        $getTipAjaxJson['admsgid']=$admsg['admsgid'];
        }else{
        	$getTipAjaxJson['haveadmsg']="0";
        }
        echo json_encode($getTipAjaxJson);
    }
}
?>